package world.criver.h50529.function;

import world.criver.h50529.module.moEvent;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class funWol {
    public String send(moEvent event){
        try {
            DatagramSocket socket = new DatagramSocket();
            byte[] address=new byte[6];
            String[] ad=event.getMac().split(":");
            System.out.println(event.getMac());
            if(ad.length!=6)return "mac地址错误";
            for(int i=0;i<ad.length;i++)address[i]= (byte) Integer.parseInt(ad[i],16);
            byte[] bs=new byte[6+16*6];
            for(int i=0;i<6;i++)bs[i]= (byte) 0xff;
            for(int i=0;i<6*16;i++)bs[i+6]=address[i%6];
            DatagramPacket packet=new DatagramPacket(bs,bs.length, InetAddress.getByName(event.getIp()),event.getPort());
            socket.send(packet);
            socket.close();
            return "已发送网络唤醒服务指令。";
        }catch (Exception e){
            e.printStackTrace();
            return event.getCommunication_mode()+"连接失败";
        }
    }
}
